﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Xml.Serialization;
using System.IO;

namespace Chianti.ViewModels
{
    public class Deal : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        string business_name;
        string short_description;

        public Deal()
        {
            Uri uri = new Uri("http://localhost/chiantiweb/handler.ashx");
            WebClient webClient = new WebClient();
            webClient.DownloadStringCompleted += OnDownloadStringCompleted;
            webClient.DownloadStringAsync(uri);
        }

        void OnDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs args)
        {
                StringReader reader = new StringReader(args.Result);
                XmlSerializer xml = new XmlSerializer(typeof(Deal));
                business_name = xml.Deserialize(reader) as String;
                short_description = xml.Deserialize(reader) as String;
        }
        
        public string BusinessName
        {
            set
            {
                if (business_name != value)
                {
                    business_name = value;
                    OnPropertyChanged("BusinessName");
                }
            }
            get
            {
                return business_name;
            }
        }

        public string ShortDescription
        {
            set
            {
                if (short_description != value)
                {
                    short_description = value;
                    OnPropertyChanged("ShortDescription");
                }
            }
            get
            {
                return short_description;
            }
        }

        protected virtual void OnPropertyChanged(string propChanged)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propChanged));
        }
    }
}
